import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;

import javax.swing.JPanel;

public class GraphicsJPanel extends JPanel
{
	private static final long serialVersionUID = 1245457179058936992L;
	ArrayList<String> maze;
	
	GraphicsJPanel(ArrayList<String> s)
	{
		maze = s;
	}
	
	public void setMaze(ArrayList<String> s)
	{
		maze = s;
	}
	
	public void paintComponent(Graphics g) 
	{
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        
        int xPlayer = 0;
        int yPlayer = 0;
        
        for (int i = 0; i < maze.size(); i++)
        {
        	String tempStr = maze.get(i);
        	
        	for (int j = 0; j < tempStr.length(); j++)
        	{
        		if (tempStr.charAt(j) == '@')
        		{
        			xPlayer = i;
        			yPlayer = j;
        		}
        	}
        }
        
        for (int x = 0; x < maze.size(); x++)
		{
        	String tStr = maze.get(x);
        	
			for (int y = 0; y < tStr.length(); y++)
			{
				char temp = tStr.charAt(y);
				
				if (temp == '@')
				{
					g2.setColor(Color.RED);
					g2.fillOval(13+(13*x), 13+(13*y), 13, 13);
				}
				else if (temp == 'X')
				{
					if (Math.abs(x-xPlayer) < 3 && Math.abs(y-yPlayer) < 3)
					{
						g2.setColor(Color.BLACK);
						g2.fillRect(13+(13*x), 13+(13*y), 13, 13);
					}
				}
				else if (temp == 'S')
				{
					if (Math.abs(x-xPlayer) < 3 && Math.abs(y-yPlayer) < 3)
					{
						g2.setColor(Color.GREEN);
						g2.fillRect(13+(13*x), 13+(13*y), 13, 13);
					}
				}
				else if (temp == 'E')
				{
					if (Math.abs(x-xPlayer) < 3 && Math.abs(y-yPlayer) < 3)
					{
						g2.setColor(Color.YELLOW);
						g2.fillRect(13+(13*x), 13+(13*y), 13, 13);
					}
				}
				else if (temp == '-')
				{
					if (Math.abs(x-xPlayer) < 3 && Math.abs(y-yPlayer) < 3)
					{
						g2.setColor(Color.BLACK);
						g2.fillRect(19+(13*x), 13+(13*y), 2, 13);
					}
				}
				else if (temp == '|')
				{
					if (Math.abs(x-xPlayer) < 3 && Math.abs(y-yPlayer) < 3)
					{
						g2.setColor(Color.BLACK);
						g2.fillRect(13+(13*x), 19+(13*y), 13, 2);
					}
				}
			}
		}
	}
}
